package com.service.impl;

import com.entity.Storage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.StorageMapper;
import com.service.StorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.utils.PageObject;
import com.vo.EmployeeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  仓库服务实现类
 * </p>
 *
 * @author aiou
 * @since 2025-06-09
 */
@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    private StorageMapper storageMapper;

    @Override
    public List<Storage> list() {
        return storageMapper.selectAll();
    }

    //仓库管理-删除
    @Override
    public boolean removeById(Integer id) {
        return storageMapper.deleteById(id);
    }

    //仓库管理-分页查询
    @Override
    public PageObject<Storage> list(PageObject pageObject) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<Storage> list = storageMapper.selectAll();
        //PageHelper包装数据
        PageInfo<Storage> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<Storage> StorageVoPageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return StorageVoPageResult;
    }

    //仓库管理-根据仓库编码查询
    @Override
    public Storage getOne(String storageCode) {
        return storageMapper.selectAllByCode(storageCode);
    }

    //仓库管理-保存
    @Override
    public boolean save(Storage storage) {
        return storageMapper.save(storage);
    }
    //仓库管理-修改
    @Override
    public boolean updateById(Storage storage) {
        return storageMapper.updateById(storage);
    }
}
